package com.hsd.znsh.security;

import com.hsd.znsh.utils.SecurityUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-23 10:29:44
 */
@Component
public class MyLogoutSuccessHandle implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        if(SecurityUtil.hasRole("ROLE_GENERAL",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/pc/user/login");
        if(SecurityUtil.hasRole("ROLE_VIP",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/pc/user/login");
        if(SecurityUtil.hasRole("ROLE_PC_MANAGER",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/pc/user/login");

        if(SecurityUtil.hasRole("ROLE_APP_MANAGER",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/app/user/login");

        if(SecurityUtil.hasRole("ROLE_BACKGROUND_MANAGER",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/manager/user/login");
        if(SecurityUtil.hasRole("ROLE_ROOT",authentication)) httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/manager/user/login");
    }
}
